package gruppoSoluzione.tests;

import gruppoSoluzione.mainService.ServiceDB;
import gruppoSoluzione.mainService.ServiceDBLog;
import gruppoSoluzione.mainService.ServiceDate;
import gruppoSoluzione.mainService.data.ServiceDBXML;

import java.util.Calendar;
import java.util.Date;

/**
 * Questo test ricrea il DB in testsDB con tutte le date anticipate al 2013
 * 
 * @author Alessandro Martinelli
 */
public class ServiceDBWriterTest {

	public static void main(String[] args) {
		
		ServiceDBXML loader=new ServiceDBXML();

		ServiceDBXML writer=new ServiceDBXML("testsDB");
		
		ServiceDB db=new ServiceDB();
		
		loader.loadDB(db);

		ServiceDB newServiceDb=new ServiceDB();
		
		for (ServiceDate serviceDate : db.getServiceDates()) {
			Date date = serviceDate.getAsDate();
			
			Iterable<ServiceDBLog> logs=db.getLogsIterable(serviceDate);
		
			Calendar calendar=Calendar.getInstance();
			calendar.setTime(date);
			calendar.set(Calendar.YEAR, 2013);
			
			ServiceDate newServiceDate=ServiceDate.fromDate(calendar.getTime());
			
			for (ServiceDBLog log : logs) {
				newServiceDb.addLog(newServiceDate, log);
			}
		}

		writer.saveDB(newServiceDb);
	}
}